#!/bin/bash

PORT=9000
CONSOLE_PORT=9001
USERNAME=admin
PASSWORD=111111
URL=localhost:9001
TAG=latest

while getopts "p:c:u:a:b:t:" opt; do
  case $opt in
    p)
        PORT=$OPTARG
        ;;
    c)
        CONSOLE_PORT=$OPTARG
        ;;
    u)
        USERNAME=$OPTARG
        ;;
    a)
        PASSWORD=$OPTARG
        ;;
    b)
        URL=$OPTARG
        ;;
    t)
        TAG=$OPTARG
        ;;
    \?)
        echo "invalid arg"
        exit 1
        ;;
  esac
done

docker run \
--restart always \
--name minio-server \
-p ${PORT}:9000 \
-p ${CONSOLE_PORT}:9001 \
-v ${PWD}/data:/data \
-e "MINIO_ROOT_USER=${USERNAME}" \
-e "MINIO_ROOT_PASSWORD=${PASSWORD}" \
-e "MINIO_SERVER_URL=${URL}" \
-d \
minio/minio:${TAG} server /data --console-address ":${CONSOLE_PORT}"